//
//  WBN_FM_PlayMoreViewController.m
//  GoodManNews
//
//  Created by 王博男 on 16/1/13.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "WBN_FM_PlayMoreViewController.h"
#import "Masonry.h"
#import "WBN_FM_MoreTableViewCell.h"
#import "GoodManNews_AFNetTool.h"
#import "WBN_FM_MoreModel.h"
#import "WBN_FM_PlayViewController.h"
#import "WBN_FM_DetailModel.h"

#define MOREURL [NSString stringWithFormat:@"http://api.3g.ifeng.com/api_fm_programlist?nodeId=%ld&page=1&pageSize=20&gv=4.6.9&av=0&proid=ifengnews&os=ios_9.2&vt=5&screen=750x1334&publishid=4002&uid=bf668f34bb83eff6208cbc233768f3ea93644221", self.nodeId]

@interface WBN_FM_PlayMoreViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableV;

@property (nonatomic, retain) NSMutableArray *arr;

@end

@implementation WBN_FM_PlayMoreViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = self.str;
    
    
    UIImage *image = [UIImage imageNamed:@"setting_close@3x"];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(barAction)];
    
    self.view.backgroundColor = [UIColor redColor];
    
    [self createView];
    [self getData];
    
}

- (void)barAction
{
    self.navigationController.navigationBar.hidden = YES;
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)createView
{
    self.tableV = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    
    self.tableV.rowHeight = 110;
    
    [self.view addSubview:self.tableV];
    [_tableV release];
    
    
    [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view);
        make.bottom.equalTo(self.view);
        make.left.equalTo(self.view);
        make.width.equalTo(self.view);
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellStr = @"cell";
    WBN_FM_MoreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    if (!cell) {
        cell = [WBN_FM_MoreTableViewCell new];
    }
    
    WBN_FM_MoreModel *model = [self.arr objectAtIndex:indexPath.row];
    
    [cell.imageV sd_setImageWithURLStr:model.programImg placeholderImage:[UIImage imageNamed:@"zhanwei.png"]];
    cell.titleL.text = model.programName;
    cell.detailL.text = model.programDetails;
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

// 进入详情
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WBN_FM_MoreModel *model = [self.arr objectAtIndex:indexPath.row];
    
    WBN_FM_PlayViewController *playerVC = [WBN_FM_PlayViewController sharePlayerViewController];
    
    playerVC.rid = [NSString stringWithFormat:@"%@", model.resourceId];
    
    [self.navigationController pushViewController:playerVC animated:YES];
}

- (void)getData
{
    [GoodManNews_AFNetTool getNetWithURL:MOREURL body:nil headFile:nil responseStyle:WBNJSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSDictionary *dic = [responseObject objectForKey:@"data"];
        NSMutableArray *arr = [dic objectForKey:@"programList"];
        self.arr = [WBN_FM_MoreModel baseModelWithArr:arr];
        
        [self.tableV reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
        
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
